<?php
// +----------------------------------------------------------------------
// | APP端会员登录控制器
// +----------------------------------------------------------------------
namespace app\common\controller;
use app\common\model\User as UserModel;
use Session;
use Request;
use Env;

class Webapp extends Base {

    protected $userinfo;
    const session_scope = 'Webapp';  //SESSION作用域
    const session_name  = 'isUser';  //SESSION值
 
    public function _initialize() {
        parent::_initialize();
        session_start();
    } 

    /**
     * 判断是否登录
     * @access protected
     * @return bool
     */
    protected function isLogin(){
        if(Session::has(self::session_name,self::session_scope)){
            return true;
        }else{
            $this->setlogoutSession();
            return FALSE;
        }
    }

     /**
     * 获取用户信息
     * @access protected
     * @return bool
     */
    protected function getLoginUser(){
        $rel = Session::get(self::session_name,self::session_scope);
        $UserModel = new UserModel;
        return $UserModel->getUserBase($rel['user_id']);
    }


    /**
     * 设置登录Session
     * @access public
     */
    protected function setLoginSession($param){
        $data = [
            'user_id'    => $param['id'],
            'login_time' => time(),
        ];
        Session::set(self::session_name,$data,self::session_scope);
    }

    /**
     * 退出Session
     * @access public
     */
    protected function setlogoutSession(){
        Session::delete(self::session_name,self::session_scope);
    } 
}
